package com.limao.CacheManager;

import com.Hazelcast.Cache;
import com.Hazelcast.CacheFactory;
import com.limao.DBDataClass.CrowdSysProjectCutClass;
import com.limao.DBProvider.SysGoodsCutProvider;
import com.limao.Tool.CacheClass;
import com.limao.cache.BasicModule;

public class SysGoodsCut_CacheManager  extends BasicModule{

	private SysGoodsCutProvider provider;
	
	private static SysGoodsCut_CacheManager instance;

    public static SysGoodsCut_CacheManager getInstance() {
        return instance;
    }

    private Cache<String, CrowdSysProjectCutClass> SysGoodsCut_CacheManager;

    public SysGoodsCut_CacheManager() {
      	super("SysGoodsCutCacheManager");
      	SysGoodsCut_CacheManager = CacheFactory.createCache("cd_GoodsCutCache");
        initProvider();
	}
    
    @Override
 	public void initialize() {
         super.initialize();
         instance=this;
     }
 
    public void ClearObjectCache(String projectid)
    {
    	CrowdSysProjectCutClass obj =SysGoodsCut_CacheManager.get(projectid);
    	if(obj!=null)
    	{
    		SysGoodsCut_CacheManager.remove(projectid);
    	}
    } 
    
    
    public CrowdSysProjectCutClass loadGoodsCut(String projectid)
    {
    	if(CacheClass.isEmpty(projectid)) return null;
    	CrowdSysProjectCutClass obj = SysGoodsCut_CacheManager.get(projectid);
		if (obj == null) {
			obj = provider.loadGoodsCut(projectid);
			if (obj != null) {
				SysGoodsCut_CacheManager.put(projectid, obj);
			}
		}
		
		return obj;
    }
    
    
    
	private void initProvider() {
		if (provider == null) {
			try {
				provider = SysGoodsCutProvider.getInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
